
const app = getApp()
import {
  HomeIndex
} from 'index-modal.js';
import {
  Config
} from '../../../utils/config.js';

var index = new HomeIndex(); //实例化 首页 对象
Page({
  data: {
    
    obj:{}
   
    
  },
  onLoad: function(options) {
   
    this.setData({
      id: options.id
    })
    this.getOrderDetail()
    
  },

  getOrderDetail(){
    let that =this;
    let data ={
      id:that.data.id,
      uid:wx.getStorageSync('members')['id']
    }
    index.getOrderDetail(data,(res)=>{
      if(res.code == 200){
        that.setData({
          obj:res.data
        })
      }
    })
  },

  gopay(e) {
    var orderid = e.currentTarget.dataset.orderid;
    var that = this;
    let data = {
      uid: wx.getStorageSync('members')['id'],
      order_id: orderid,
      coupon_id: that.data.cou_id,
      type: 1,
      form_id: e.detail.formId
    }
    
    index.wePayment(data, (res) => {
      if (res.code == 200) {
        wx.requestPayment({
          'timeStamp': res.data.timeStamp.toString(),
          'nonceStr': res.data.nonceStr,
          'package': res.data.package,
          'signType': res.data.signType,
          'paySign': res.data.paySign,
          success: function(ress) {
            that.getOrderDetail();
          },
          success (res) { },
          fail (res) { }
        })
      }
    })
  },

})